﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Acoris.Media
{
    using Acoris.Rendering;

#if NET_UWP
    using Windows.UI;
#endif

#if WIN2D
    using Microsoft.Graphics.Canvas.Brushes;
#endif

    /// <summary>
    /// 描述一个纯色画刷
    /// </summary>
    public sealed class SolidColorBrush : Brush
    {
        internal Color m_color;
        internal bool CachedResult;

#if WIN2D
        internal ICanvasBrush CachedBrush;
#endif

        public SolidColorBrush(Color color)
        {
            m_color = color;
        }

        /// <summary>
        /// 获取当前的颜色
        /// </summary>
        public Color Color {
            get { return m_color; }
        }        

        #region Override

        /// <summary>
        /// 获取与当前对象等价的字符串形式
        /// </summary>
        /// <returns>返回与当前对象等价的字符串形式</returns>
        public override string ToString()
        {
            return m_color.ToString();
        }

        /// <summary>
        /// 获取当前对象与指定对象之间的等价性
        /// </summary>
        /// <param name="obj">指定要比较的对象</param>
        /// <returns>如果两个对象之间等价则返回true，否则返回false</returns>
        public override bool Equals(object obj)
        {
            if (obj is SolidColorBrush scb) {
                return scb.m_color == this.m_color;
            }
            return false;
        }

        /// <summary>
        /// 获取当前对象的哈希值
        /// </summary>
        /// <returns>返回当前对象的哈希值</returns>
        public override int GetHashCode()
        {
            return base.GetHashCode() ^ m_color.GetHashCode();
        }

        /// <summary>
        /// 
        /// </summary>
        public override void Dispose()
        {
#if WIN2D
            CachedBrush?.Dispose();
#endif
        }

        #endregion

        #region operator == / !=

        public static bool operator ==(SolidColorBrush x, SolidColorBrush y)
        {
            return x.m_color == y.m_color;
        }

        public static bool operator !=(SolidColorBrush x, SolidColorBrush y)
        {
            return x.m_color != y.m_color;
        }

        #endregion
    }
}
